package rpc.server.main;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;
import org.junit.Before;
import org.junit.Test;
import rpc.server.MyInterface;
import rpc.server.impl.MyInterfaceImpl;

import java.io.IOException;

/**
 * ServerMain
 *
 * @author zhangyimin
 * @version 1.0
 * @date 2018-07-27 下午3:18
 */
public class ServerMain {


    public static Configuration configuration;
    public final  static  String hostName="zymMBP";
    public final  static  int port=7788;


    /**
     * 测试RPC协议
     * @throws IOException
     */
    @Test
    public void testServer() throws IOException {
        RPC.Builder builder=new RPC.Builder(configuration);
        builder.setBindAddress(hostName);
        builder.setPort(port);
        builder.setProtocol(MyInterface.class);
        builder.setInstance(new MyInterfaceImpl());
        RPC.Server server=builder.build();
        server.start();
    }

    @Before
    public void setConfig() throws IOException {
        configuration = new Configuration();
        configuration.set("fs.defaultFS", "hdfs://10.16.7.37:9000");
    }


    public static void main(String[] args) throws Exception {
        configuration = new Configuration();
        configuration.set("fs.defaultFS", "hdfs://10.16.7.37:9000");
        RPC.Builder builder=new RPC.Builder(configuration);
        builder.setBindAddress(hostName);
        builder.setPort(port);
        builder.setProtocol(MyInterface.class);
        builder.setInstance(new MyInterfaceImpl());
        RPC.Server server=builder.build();
        server.start();
    }



}
